document.addEventListener('DOMContentLoaded', function() {
    // 侧边栏折叠功能
    const sidebarCollapse = document.getElementById('sidebarCollapse');
    const sidebar = document.getElementById('sidebar');
    const content = document.getElementById('content');

    if (sidebarCollapse) {
        sidebarCollapse.addEventListener('click', function() {
            sidebar.classList.toggle('active');
            content.classList.toggle('active');
        });
    }


    function checkWidth() {
        if (window.innerWidth <= 768) {
            sidebar.classList.add('active');
            content.classList.add('active');
        } else {
            sidebar.classList.remove('active');
            content.classList.remove('active');
        }
    }

    // 初始检查
    checkWidth();

    // 监听窗口大小变化
    window.addEventListener('resize', checkWidth);

    const currentPath = window.location.pathname;
    const menuItems = document.querySelectorAll('#sidebar ul li a');

    menuItems.forEach(item => {
        if (item.getAttribute('href') === currentPath) {
            item.parentElement.classList.add('active');
        } else {
            item.parentElement.classList.remove('active');
        }
    });
});